package mortal.game.manager
{
	import com.gengine.global.*;
	import com.mui.core.*;
	import flash.display.*;
	import flash.events.*;
	import flash.ui.*;
	
	public class CursorManagerImpl extends Sprite
	{
		private var _cursorSkin:MovieClip;
		private var _cursorStyle:String;
		
		public function CursorManagerImpl()
		{
			this.addEventListener(Event.ADDED_TO_STAGE, this.addedToStageHandler);
		}
		
		public function addedToStageHandler(event:Event) : void
		{
			this.mouseChildren = false;
			this.mouseEnabled = false;
			this._cursorSkin = GlobalClass.getInstance("CursorSkin");
			this._cursorSkin.mouseChildren = false;
			this._cursorSkin.mouseEnabled = false;
			this.cursorStyle = CursorManager.NO_CURSOR;
			this.addChild(this._cursorSkin);
		}
		
		private function onMouseMoveHandler(event:MouseEvent) : void
		{
			this._cursorSkin.x = event.stageX;
			this._cursorSkin.y = event.stageY;
			event.updateAfterEvent();
		}
		
		public function dispose() : void
		{
		}
		
		public function get cursorStyle() : String
		{
			return this._cursorStyle;
		}
		
		public function set cursorStyle(cursorStyle:String) : void
		{
			this._cursorStyle = cursorStyle;
			if (this._cursorStyle == CursorManager.NO_CURSOR)
			{
				if (this.contains(this._cursorSkin))
				{
					this.removeChild(this._cursorSkin);
				}
				Mouse.show();
				Global.stage.removeEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMoveHandler);
			}
			else
			{
				if (this.contains(this._cursorSkin) == false)
				{
					this.addChild(this._cursorSkin);
				}
				Mouse.hide();
				this._cursorSkin.gotoAndStop(cursorStyle);
				this._cursorSkin.x = mouseX;
				this._cursorSkin.y = mouseY;
				Global.stage.addEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMoveHandler);
			}
		}
	}
}
